<template>
  <div>

    <el-form :inline="true" :model="user" class="demo-form-inline">
      <el-form-item label="用户">
        <el-input v-model="user.username" placeholder="用户"></el-input>
      </el-form-item>
      <el-form-item label="公司名称">
        <el-input v-model="user.company" placeholder="公司名称"></el-input>
      </el-form-item>

      <el-form-item label="手机号">
        <el-input v-model="user.phone" placeholder="手机号"></el-input>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" @click="list">查询</el-button>
      </el-form-item>
    </el-form>


    <el-table
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column
          fixed
          prop="id"
          label="id"
          width="150">
      </el-table-column>
      <el-table-column
          prop="username"
          label="姓名"
          width="120">
      </el-table-column>
      <el-table-column
          prop="cname"
          label="中文名"
          width="120">
      </el-table-column>
      <el-table-column
          prop="phone"
          label="phone"
          width="120">
      </el-table-column>
      <el-table-column
          prop="address"
          label="地址"
          width="300">
      </el-table-column>
      <el-table-column
          prop="job"
          label="job"
          width="120">
      </el-table-column>

      <el-table-column
          prop="company"
          label="公司名称"
          width="120">
      </el-table-column>


      <el-table-column
          prop="created"
          label="创建时间"
          width="120">
      </el-table-column>
      <el-table-column
          fixed="right"
          label="操作"
          width="200">
        <template slot-scope="scope">
          <el-button @click="del(scope.row.id)" type="text" size="small">逻辑删除</el-button>
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @current-change="goPage"
        :page-size="10"
        layout="total, prev, pager, next"
        :total="total">
    </el-pagination>
  </div>

</template>

<script>
export default {
  name: "UserView",
  data() {
    return {
      tableData:[],
      pageNum:1,
      user:{},
      total:0,
    }
  }, methods: {
    del(id){
      this.axios.get("user/del?id="+id).then(res=>{
        if(res.data.code==200){
          this.$message.success(res.data.msg);
          this.list();
        }else{
          this.$message.error(res.data.msg);
        }
      })
    },
    goPage(page){
      this.pageNum=page;
      this.list();
    },
     list(){
       this.axios.post("user/list?pageNum="+this.pageNum,this.user).then(res=>{
         this.tableData = res.data.data.list;
         this.total =res.data.data.total;
       })
     }

  }, created() {

    this.list();
  }
}
</script>

<style scoped>

</style>